package first;

import java.util.Arrays;

public class ToStringTest {
    public static void main(String[] args) {
//        int[] arr = {1,2,3,4,5,6};
        int[] arr = {1,2,3};

        System.out.println("数组内容： "+ Arrays.toString(arr));
        System.out.println("数组内容222： "+ ToStringTest.toString(arr));

    }
    public static String toString(int[] arr){
        if (arr == null){
            return "null";
        }else if (arr.length == 0){
            return "[]";
        }
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < arr.length; i++) {
            int index = arr[i];
            if (i == 0){
                str.append("["+index);
                if (arr.length == 1){
                    str.append("]");
                }
            }else if(i == arr.length-1){
                str.append(", "+index+"]");
            }else {
                str.append(", "+index);
            }
        }
        return str.toString();
    }
}
